/**
 * Created by Wesley on 2021/9/13.
 */
var age;
age = 10;
console.log("age = " + age);
age = "ten";
console.log("age = " + age);

var number = 2;
var price = 29.9;
var total = number * price;

/*字符串转换成数据类型*/
age = '10';/*确定了当前数据类型为String字符串*/
//转换成整数类型
var a1 = parseInt(age);
console.log('a1: ' + typeof (a1));

price = '29.9';
var p1 = parseFloat(price);
console.log('price:' + typeof (p1));

//数组
var names = new Array('任宇翔','马博','王保财','李威');
for(var i = 0;i < names.length;i++){
    console.log(names[i]);
}
var cars = ['宝马','奔驰','奥迪'];
for(i = 0;i<cars.length;i++){
    console.log(cars[i]);
}

//对象
var person1 = {
    perName:'Smith',
    perAge:15,
    perAddress:'苏州'
};
console.log(person1.perName);
console.log(person1.perAge);
console.log(person1.perAddress);
//商品对象
var pro1 = {
    proId:18965644,
    proName:'消毒纸巾',
    proPrice:23.9
};
var pro2 = {
    proId:155787136,
    proName:'天堂雨伞',
    proPrice:23.9
};
var pro3 = {
    proId:486853568,
    proName:'飞科剃须刀',
    proPrice:23.9
};
var proArray1 = [pro1,pro2,pro3];
var proArray2 = [
    {
    proId:18965644,
    proName:'消毒纸巾',
    proPrice:23.9
    },
    {
        proId:155787136,
        proName:'天堂雨伞',
        proPrice:39.9
    },
    {
        proId:486853568,
        proName:'飞科剃须刀',
        proPrice:99.9
    }
];
//for(i = 0;i < proArray2.length ; i++){
//    console.log(proArray2[i]);
//}

for(var i in proArray2){
    console.log(proArray2[i]);
}
console.log('pro1的数据类型：' + typeof (pro1));

//定义函数（方法）
function fun1(){
    console.log('fun1');
}
//调用方法
fun1();
function fun2(name,age){
    console.log('fun2 name:' + name,',age:' + age);
}
fun2("Smith",23);
function fun3(a,b){
    return a+b;
}
var fun3 =  fun3(10,5.5);
console.log('fun3的返回值：' + fun3);